package com.pandora.credit.mongo.entity;

import com.pandora.common.util.VerifyUtil;
import com.pandora.credit.exception.InvalidDataException;

/**
 * @author developer
 */
public class WmConvertReportFormat extends AbstractReportAfterFormat {
    @Override
    protected ReportMetaData getMetaDataByReport(AbstractReport report) {
        WmReport wmReport = (WmReport)report;

        WmReportMetaData metaData = new WmReportMetaData();
        WmDataSource ds = wmReport.getDataSource();
        String mobile;
        long reportId;
        String name;
        if (ds != null) {
            mobile = ds.getMobile();
            if (VerifyUtil.isEmpty(mobile)) {
                logger.info("no mobile in the report");
                throw new InvalidDataException("报告中未找到用户手机信息!");
            }
            metaData.setMobile(mobile);

            reportId = wmReport.getReportId();
            if (reportId <= 0) {
                logger.info("no report id in the report");
                throw new InvalidDataException("报告中未找到用报告id!");
            }
            metaData.setReportId(reportId);

            name = ds.getName();
            if (VerifyUtil.isEmpty(name)) {
                logger.info("no food order type in the report");
                throw new InvalidDataException("报告中未找到外卖类型信息!");
            }
            metaData.setWmType(name);
        } else {
            logger.info("no data source in the report");
            throw new InvalidDataException("报告中未找到DataSource!");
        }
        return metaData;
    }

    @Override
    protected AbstractReport dealReportData(AbstractReport report) {
        WmReport wmReport = (WmReport)report;
        if(wmReport.getOrderList() != null) {
            wmReport.setOrderList(null);
        }
        return wmReport;
    }
}
